package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Archives;
import com.ruoyi.system.service.IArchivesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 档案信息Controller
 * 
 * @author CXY
 * @date 2024-01-10
 */
@RestController
@RequestMapping("/system/archives")
public class ArchivesController extends BaseController
{
    @Autowired
    private IArchivesService archivesService;

    /**
     * 查询档案信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:archives:list')")
    @GetMapping("/list")
    public TableDataInfo list(Archives archives)
    {
        startPage();
        List<Archives> list = archivesService.selectArchivesList(archives);
        return getDataTable(list);
    }

    /**
     * 导出档案信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:archives:export')")
    @Log(title = "档案信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Archives archives)
    {
        List<Archives> list = archivesService.selectArchivesList(archives);
        ExcelUtil<Archives> util = new ExcelUtil<Archives>(Archives.class);
        util.exportExcel(response, list, "档案信息数据");
    }

    /**
     * 获取档案信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:archives:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(archivesService.selectArchivesById(id));
    }

    /**
     * 新增档案信息
     */
    @PreAuthorize("@ss.hasPermi('system:archives:add')")
    @Log(title = "档案信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Archives archives)
    {
        return toAjax(archivesService.insertArchives(archives));
    }

    /**
     * 修改档案信息
     */
    @PreAuthorize("@ss.hasPermi('system:archives:edit')")
    @Log(title = "档案信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Archives archives)
    {
        return toAjax(archivesService.updateArchives(archives));
    }

    /**
     * 删除档案信息
     */
    @PreAuthorize("@ss.hasPermi('system:archives:remove')")
    @Log(title = "档案信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(archivesService.deleteArchivesByIds(ids));
    }

    /** 借阅 */
    @PreAuthorize("@ss.hasPermi('system:archives:borrow')")
    @GetMapping(value = "/borrow")
    public AjaxResult borrow(Archives archives)
    {
        return AjaxResult.success("Borrow success!");
    }
}
